home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / include / coff.h < prev    next >
C/C++ Source or Header  |  1996-01-30  |  10KB  |  310 lines

  1. /*** coff information for Intel 386/486.  */
  2.  
  3. /********************** FILE HEADER **********************/
  4.  
  5. struct external_filehdr {
  6.     unsigned short f_magic;        /* magic number            */
  7.     unsigned short f_nscns;        /* number of sections        */
  8.     unsigned long f_timdat;    /* time & date stamp        */
  9.     unsigned long f_symptr;    /* file pointer to symtab    */
  10.     unsigned long f_nsyms;        /* number of symtab entries    */
  11.     unsigned short f_opthdr;    /* sizeof(optional hdr)        */
  12.     unsigned short f_flags;        /* flags            */
  13. };
  14.  
  15.  
  16. /* Bits for f_flags:
  17.  *    F_RELFLG    relocation info stripped from file
  18.  *    F_EXEC        file is executable (no unresolved external references)
  19.  *    F_LNNO        line numbers stripped from file
  20.  *    F_LSYMS        local symbols stripped from file
  21.  *    F_AR32WR    file has byte ordering of an AR32WR machine (e.g. vax)
  22.  */
  23.  
  24. #define F_RELFLG    (0x0001)
  25. #define F_EXEC        (0x0002)
  26. #define F_LNNO        (0x0004)
  27. #define F_LSYMS        (0x0008)
  28.  
  29.  
  30.  
  31. #define    I386MAGIC    0x14c
  32. #define I386AIXMAGIC    0x175
  33. #define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
  34.  
  35.  
  36. #define    FILHDR    struct external_filehdr
  37. #define    FILHSZ    sizeof(FILHDR)
  38.  
  39.  
  40. /********************** AOUT "OPTIONAL HEADER" **********************/
  41.  
  42.  
  43. typedef struct 
  44. {
  45.   unsigned short     magic;        /* type of file                */
  46.   unsigned short    vstamp;        /* version stamp            */
  47.   unsigned long    tsize;        /* text size in bytes, padded to FW bdry*/
  48.   unsigned long    dsize;        /* initialized data "  "        */
  49.   unsigned long    bsize;        /* uninitialized data "   "        */
  50.   unsigned long    entry;        /* entry pt.                */
  51.   unsigned long     text_start;    /* base of text used for this file */
  52.   unsigned long     data_start;    /* base of data used for this file */
  53. }
  54. AOUTHDR;
  55.  
  56.  
  57. typedef struct gnu_aout {
  58.     unsigned long info;
  59.     unsigned long tsize;
  60.     unsigned long dsize;
  61.     unsigned long bsize;
  62.     unsigned long symsize;
  63.     unsigned long entry;
  64.     unsigned long txrel;
  65.     unsigned long dtrel;
  66.     } GNU_AOUT;
  67.  
  68. #define AOUTSZ (sizeof(AOUTHDR))
  69.  
  70. #define OMAGIC          0404    /* object files, eg as output */
  71. #define ZMAGIC          0413    /* demand load format, eg normal ld output */
  72. #define STMAGIC        0401    /* target shlib */
  73. #define SHMAGIC        0443    /* host   shlib */
  74.  
  75.  
  76. /********************** SECTION HEADER **********************/
  77.  
  78.  
  79. struct external_scnhdr {
  80.     char        s_name[8];    /* section name            */
  81.     unsigned long        s_paddr;    /* physical address, aliased s_nlib */
  82.     unsigned long        s_vaddr;    /* virtual address        */
  83.     unsigned long        s_size;        /* section size            */
  84.     unsigned long        s_scnptr;    /* file ptr to raw data for section */
  85.     unsigned long        s_relptr;    /* file ptr to relocation    */
  86.     unsigned long        s_lnnoptr;    /* file ptr to line numbers    */
  87.     unsigned short        s_nreloc;    /* number of relocation entries    */
  88.     unsigned short        s_nlnno;    /* number of line number entries*/
  89.     unsigned long        s_flags;    /* flags            */
  90. };
  91.  
  92. #define    SCNHDR    struct external_scnhdr
  93. #define    SCNHSZ    sizeof(SCNHDR)
  94.  
  95. /*
  96.  * names of "special" sections
  97.  */
  98. #define _TEXT    ".text"
  99. #define _DATA    ".data"
  100. #define _BSS    ".bss"
  101. #define _COMMENT ".comment"
  102. #define _LIB ".lib"
  103.  
  104. /*
  105.  * s_flags "type"
  106.  */
  107. #define STYP_TEXT     (0x0020)    /* section contains text only */
  108. #define STYP_DATA     (0x0040)    /* section contains data only */
  109. #define STYP_BSS     (0x0080)    /* section contains bss only */
  110.  
  111. /********************** LINE NUMBERS **********************/
  112.  
  113. /* 1 line number entry for every "breakpointable" source line in a section.
  114.  * Line numbers are grouped on a per function basis; first entry in a function
  115.  * grouping will have l_lnno = 0 and in place of physical address will be the
  116.  * symbol table index of the function name.
  117.  */
  118. struct external_lineno {
  119.     union {
  120.         unsigned long l_symndx __attribute__((packed));    /* function name symbol index, iff l_lnno == 0 */
  121.         unsigned long l_paddr __attribute__((packed));        /* (physical) address of line number */
  122.     } l_addr;
  123.     unsigned short l_lnno;                        /* line number */
  124. };
  125.  
  126.  
  127. #define    LINENO    struct external_lineno
  128. #define    LINESZ    sizeof(LINENO)
  129.  
  130.  
  131. /********************** SYMBOLS **********************/
  132.  
  133. #define E_SYMNMLEN    8    /* # characters in a symbol name    */
  134. #define E_FILNMLEN    14    /* # characters in a file name        */
  135. #define E_DIMNUM    4    /* # array dimensions in auxiliary entry */
  136.  
  137. struct external_syment 
  138. {
  139.   union {
  140.     char e_name[E_SYMNMLEN];
  141.     struct {
  142.       unsigned long e_zeroes __attribute__((packed));
  143.       unsigned long e_offset __attribute__((packed));
  144.     } e;
  145.   } e;
  146.   unsigned long e_value __attribute__((packed));
  147.   short e_scnum;
  148.   unsigned short e_type;
  149.   unsigned char e_sclass;
  150.   unsigned char e_numaux;
  151. };
  152.  
  153. #define N_BTMASK    (0xf)
  154. #define N_TMASK        (0x30)
  155. #define N_BTSHFT    (4)
  156. #define N_TSHIFT    (2)
  157.   
  158. union external_auxent {
  159.     struct {
  160.         unsigned long x_tagndx __attribute__((packed));        /* str, un, or enum tag indx */
  161.         union {
  162.             struct {
  163.                 unsigned short  x_lnno;                /* declaration line number */
  164.                 unsigned short  x_size;                 /* str/union/array size */
  165.             } x_lnsz;
  166.             unsigned long x_fsize __attribute__((packed));        /* size of function */
  167.         } x_misc;
  168.         union {
  169.             struct {                    /* if ISFCN, tag, or .bb */
  170.                 unsigned long x_lnnoptr __attribute__((packed));    /* ptr to fcn line # */
  171.                 unsigned long x_endndx __attribute__((packed));    /* entry ndx past block end */
  172.             } x_fcn;
  173.             struct {                    /* if ISARY, up to 4 dimen. */
  174.                 unsigned short x_dimen[E_DIMNUM];
  175.             } x_ary;
  176.         } x_fcnary;
  177.         unsigned short x_tvndx;                        /* tv index */
  178.     } x_sym;
  179.  
  180.     union {
  181.         char x_fname[E_FILNMLEN];
  182.         struct {
  183.             unsigned long x_zeroes __attribute__((packed));
  184.             unsigned long x_offset __attribute__((packed));
  185.         } x_n;
  186.     } x_file;
  187.  
  188.     struct {
  189.         unsigned long x_scnlen __attribute__((packed));        /* section length */
  190.         unsigned short x_nreloc;                    /* # relocation entries */
  191.         unsigned short x_nlinno;                    /* # line numbers */
  192.     } x_scn;
  193.  
  194.         struct {
  195.         unsigned long x_tvfill __attribute__((packed));        /* tv fill value */
  196.         unsigned short x_tvlen;                        /* length of .tv */
  197.         unsigned short x_tvran[2];                    /* tv range */
  198.     } x_tv;        /* info about .tv section (in auxent of symbol .tv)) */
  199.  
  200.  
  201. };
  202.  
  203. #define    SYMENT    struct external_syment
  204. #define    SYMESZ    sizeof(SYMENT)
  205. #define    AUXENT    union external_auxent
  206. #define    AUXESZ    sizeof(AUXENT)
  207.  
  208.  
  209. #    define _ETEXT    "etext"
  210.  
  211.  
  212. /* Relocatable symbols have number of the section in which they are defined,
  213.    or one of the following: */
  214.  
  215. #define N_UNDEF    ((short)0)    /* undefined symbol */
  216. #define N_ABS    ((short)-1)    /* value of symbol is absolute */
  217. #define N_DEBUG    ((short)-2)    /* debugging symbol -- value is meaningless */
  218. #define N_TV    ((short)-3)    /* indicates symbol needs preload transfer vector */
  219. #define P_TV    ((short)-4)    /* indicates symbol needs postload transfer vector*/
  220.  
  221. /*
  222.  * Type of a symbol, in low N bits of the word
  223.  */
  224. #define T_NULL        0
  225. #define T_VOID        1    /* function argument (only used by compiler) */
  226. #define T_CHAR        2    /* character        */
  227. #define T_SHORT        3    /* short integer    */
  228. #define T_INT        4    /* integer        */
  229. #define T_LONG        5    /* long integer        */
  230. #define T_FLOAT        6    /* floating point    */
  231. #define T_DOUBLE    7    /* double word        */
  232. #define T_STRUCT    8    /* structure         */
  233. #define T_UNION        9    /* union         */
  234. #define T_ENUM        10    /* enumeration         */
  235. #define T_MOE        11    /* member of enumeration*/
  236. #define T_UCHAR        12    /* unsigned character    */
  237. #define T_USHORT    13    /* unsigned short    */
  238. #define T_UINT        14    /* unsigned integer    */
  239. #define T_ULONG        15    /* unsigned long    */
  240. #define T_LNGDBL    16    /* long double        */
  241.  
  242. /*
  243.  * derived types, in n_type
  244. */
  245. #define DT_NON        (0)    /* no derived type */
  246. #define DT_PTR        (1)    /* pointer */
  247. #define DT_FCN        (2)    /* function */
  248. #define DT_ARY        (3)    /* array */
  249.  
  250. #define BTYPE(x)    ((x) & N_BTMASK)
  251.  
  252. #define ISPTR(x)    (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  253. #define ISFCN(x)    (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  254. #define ISARY(x)    (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  255. #define ISTAG(x)    ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
  256. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  257.  
  258. /********************** STORAGE CLASSES **********************/
  259.  
  260. /* This used to be defined as -1, but now n_sclass is unsigned.  */
  261. #define C_EFCN        0xff    /* physical end of function    */
  262. #define C_NULL        0
  263. #define C_AUTO        1    /* automatic variable        */
  264. #define C_EXT        2    /* external symbol        */
  265. #define C_STAT        3    /* static            */
  266. #define C_REG        4    /* register variable        */
  267. #define C_EXTDEF    5    /* external definition        */
  268. #define C_LABEL        6    /* label            */
  269. #define C_ULABEL    7    /* undefined label        */
  270. #define C_MOS        8    /* member of structure        */
  271. #define C_ARG        9    /* function argument        */
  272. #define C_STRTAG    10    /* structure tag        */
  273. #define C_MOU        11    /* member of union        */
  274. #define C_UNTAG        12    /* union tag            */
  275. #define C_TPDEF        13    /* type definition        */
  276. #define C_USTATIC    14    /* undefined static        */
  277. #define C_ENTAG        15    /* enumeration tag        */
  278. #define C_MOE        16    /* member of enumeration    */
  279. #define C_REGPARM    17    /* register parameter        */
  280. #define C_FIELD        18    /* bit field            */
  281. #define C_AUTOARG    19    /* auto argument        */
  282. #define C_LASTENT    20    /* dummy entry (end of block)    */
  283. #define C_BLOCK        100    /* ".bb" or ".eb"        */
  284. #define C_FCN        101    /* ".bf" or ".ef"        */
  285. #define C_EOS        102    /* end of structure        */
  286. #define C_FILE        103    /* file name            */
  287. #define C_LINE        104    /* line # reformatted as symbol table entry */
  288. #define C_ALIAS         105    /* duplicate tag        */
  289. #define C_HIDDEN    106    /* ext symbol in dmert public lib */
  290.  
  291. /********************** RELOCATION DIRECTIVES **********************/
  292.  
  293.  
  294.  
  295. struct external_reloc {
  296.   unsigned long r_vaddr __attribute__((packed));
  297.   unsigned long r_symndx __attribute__((packed));
  298.   unsigned short r_type;
  299. };
  300.  
  301.  
  302. #define RELOC struct external_reloc
  303. #define RELSZ sizeof(RELOC)
  304.  
  305. #define DEFAULT_DATA_SECTION_ALIGNMENT 4
  306. #define DEFAULT_BSS_SECTION_ALIGNMENT 4
  307. #define DEFAULT_TEXT_SECTION_ALIGNMENT 4
  308. /* For new sections we havn't heard of before */
  309. #define DEFAULT_SECTION_ALIGNMENT 4
  310.